<template>
  <div>
    <home-header></home-header>
    <home-swiper :list='list'></home-swiper>
    <home-icon :icon="icon"></home-icon>
    <home-recommend :reconmend="reconmend"></home-recommend>
    <home-weekend :weekend="weekend"></home-weekend>
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcon from './components/Icon'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  name: 'Home',
  data () {
    return {
      list: [],
      icon: [],
      reconmend: [],
      weekend: [],
      lateCity: ''
    }
  },
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcon,
    HomeRecommend,
    HomeWeekend
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      res = res.data
      if (res.data && res.ret) {
        const data = res.data
        this.list = data.swiperList
        this.icon = data.iconList
        this.reconmend = data.recommendList
        this.weekend = data.weekendList
      }
    }
  },
  mounted () {
    this.getHomeInfo()
    this.lateCity = this.city
  },
  computed: {
    ...mapState(['city'])
  },
  activated () {
    if (this.lateCity !== this.city) {
      this.lateCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style>

</style>
